package collection.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StreamApiDemo2 {
    public static void main(String[] args) {
        Random rand = new Random();
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<10;i++){
            list.add(rand.nextInt(100));
        }
        System.out.println(list);
        /*
        1.min
        2.max
         */
        Optional<Integer> value = list.stream().min((e1,e2)->e1-e2);
        System.out.println(value.get());

        value = list.stream().max((e1,e2)->e1-e2);
        System.out.println(value.get());

        boolean anyMatch = list.stream().anyMatch(e->e%2==0);//有偶数则为true
        System.out.println(anyMatch);

        boolean allMatch = list.stream().allMatch(e->e%2==0);//所有都是偶数则为true
        System.out.println(allMatch);

        boolean noneMatch = list.stream().noneMatch(e->e%2==0);//一个偶数都没有则为true
        System.out.println(noneMatch);

        int number = list.stream().reduce((e1,e2)->e1+e2).get();//所有元素求和
        System.out.println(number);

    }
}
